Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Social Media Photo by Lucrezia Carnelos on Unsplash
React like hooks for the masses.
{sync: true, always: true}
second parameter to force sync updates, async by default, and always call the hook, even if the state is the same, false by default.createContext(value)
{sync: true, always: true}
second parameter to force sync updates, async by default, and always call the hook, even if the state is the same, false by default.dropEffect(augmentedCallback)
executes any cleanup left from last useEffect(...)
invocationYou can test this example directly on Code Pen.
import {augmentor, useState} from 'augmentor';
// augment any function once
const a = augmentor(test);
a();
// ... or many times ...
const [b, c] = [test, test].map(augmentor);
b();
c();
function test() {
const [count, setCount] = useState(0);
// log current count value
console.log(count);
// will invoke this augmented function each second
setTimeout(() => setCount(count + 1), 1000);
}
augmented.call(ctx)
or augmented.apply(ctx, [])
, 'cause no context whatsoever is passed along.
If by any chance you've read, and understood, the related blog post, you'd realize a single augmented function is indeed not good for prototypes or shared methods, as one context could interfere with any other previous context that used that method before.
// WRONG: this is a very bad idea, as any MyComp instance
// could potentially interfere with other instances
MyComp.prototype.doThings = augmentor(doThings);
// GOOD: this is how you'd do it 👍
class MyComp {
constructor() {
const {doThings} = this;
// augment a bound method/function per each instance
this.doThings = augmentor(doThings.bind(this));
}
doThings() {
// where actually you do hooky-things
}
}
That being said, if you really want to share a context within a single augmented function, meaning that you understand, and know, what you are doing, you can
use the contextual
utility provided by this library.
import {contextual} from 'augmentor';
const textInjector = contextual(function (text) {
this.textContent = text;
});
textInjector.call(div, 'hello');
textInjector.call(p, 'there!');
Please bear in mind that contextualized functions effects will also refer to the previous context, not necessarily the current one, so that you see it's very easy to create troubles sharing, accepting, or passing, multiple contexts to the same augmented stack.
As summary, augmentor(method.bind(context))
is the best way to use a context within an augmented function, but contextual
can help covering other weird edge cases too.
FAQs
React like hooks for the masses
We found that augmentor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.